﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCEntity.CRM.CustomerReceptionRecord;
using BCService.CRM.CustomerReceptionRecord;
using BCDto.CRM.CustomerReceptionRecord;

namespace BCTMSRESTful.Controllers.Management.CRM.CustomerReceptionRecord
{
    /// <summary>
    /// 客户接待记录接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class CustomerReceptionRecordController : ManagementBaseController
    {
        #region var
        private ICustomerReceptionRecordService cCustomerReceptionRecordService;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public CustomerReceptionRecordController(ICustomerReceptionRecordService ccCustomerReceptionRecordService)
        {
            this.cCustomerReceptionRecordService = ccCustomerReceptionRecordService;
        }
        #endregion

        #region POST
        /// <summary>
        /// 创建客户接待记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPost]        
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult Post([FromBody]CustomerReceptionRecordRequestDto dto)
        {
        
            var a = this.cCustomerReceptionRecordService.Insert(this.Admin,dto);
            return Ok(a);
        }

        #endregion

        #region PUT
        /// <summary>
        /// 修改客户接待记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPut]        
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult Put([FromBody]CustomerReceptionRecordDto dto)
        {
            var a = Ok(cCustomerReceptionRecordService.Update(this.Admin,dto));
            return a;
        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除客户接待记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{customer_reception_record_id}")]        
        [ProducesResponseType(typeof(CustomerReceptionRecordDto), 200)]
        public IActionResult Delete([FromRoute(Name = "customer_reception_record_id")]long id)
        {
             cCustomerReceptionRecordService.Delete(id);
            return NoContent();
        }
        #endregion

        #region GetByID 
        /// <summary>
        /// 获取客户接待记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpGet("{customer_reception_record_id}")]        
        [ProducesResponseType(typeof(CustomerReceptionRecordDto), 200)]
        public IActionResult GetByID([FromRoute(Name = "customer_reception_record_id")]long ccID)
        {
            var a = Ok(cCustomerReceptionRecordService.GetByID(ccID));
            return a;
        }
        #endregion

        #region GetList 
        /// <summary>
        ///  分页获取客户接待记录
        /// </summary>
        /// <param name="arrivalTimeBegin"></param>
        /// <param name="arrivalTimeEnd"></param>
        /// <param name="exitTimeBegin"></param>
        /// <param name="exitTimeEnd"></param>
        /// <param name="ccUserName"></param>
        /// <param name="ccPhone"></param>
        /// <param name="ccEmail"></param>
        /// <param name="ccProvinceId"></param>
        /// <param name="ccCityId"></param>
        /// <param name="ccCountyId"></param>
        /// <param name="ccPageNo"></param>
        /// <param name="ccPageSize"></param>
        /// <returns></returns>
        [HttpGet] 
        [ProducesResponseType(typeof(PageableList<CustomerReceptionRecordDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "arrival_time_begin")] DateTime? arrivalTimeBegin,
                                                    [FromQuery(Name = "arrival_time_end")] DateTime? arrivalTimeEnd,
                                                    [FromQuery(Name = "exit_time_begin")] DateTime? exitTimeBegin,
                                                    [FromQuery(Name = "exit_time_end")]  DateTime? exitTimeEnd,
                                                    [FromQuery(Name = "user_name")]  string ccUserName,
                                                    [FromQuery(Name = "phone")]  string ccPhone,
                                                    [FromQuery(Name = "email")]  string ccEmail,
                                                    [FromQuery(Name = "province_code")] string ccProvinceId,
                                                    [FromQuery(Name = "city_code")]  string ccCityId,
                                                    [FromQuery(Name = "county_code")]  string ccCountyId,
                                                    [FromQuery(Name = "index")]    int? ccPageNo = 1,
                                                    [FromQuery(Name = "size")]    int? ccPageSize = 10) 
        {
            Console.WriteLine(string.Format("{0},{1},{2},{3}", arrivalTimeBegin, arrivalTimeEnd, exitTimeBegin, exitTimeEnd));
            var a = cCustomerReceptionRecordService.GetList(this.Admin, arrivalTimeBegin, arrivalTimeEnd, exitTimeBegin, exitTimeEnd, ccUserName, ccPhone, ccEmail, ccProvinceId, ccCityId, ccCountyId, ccPageNo.Value, ccPageSize.Value);
            return Ok(a);
        }
        #endregion
    }
}
